package com.foreveross.fetl.application.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.foreveross.fetl.application.IExchangeRateApplication;
import com.foreveross.fetl.core.domain.task.ExchangeRateEntity;
import com.foreveross.fetl.vo.ExchangeRateVO;

@Transactional(value="transactionManagerOracle")
@Service("exchangeRateApplication")
public class ExchangeRateApplicationImpl implements IExchangeRateApplication {

	@Override
	public void save(ExchangeRateVO vo) {
		ExchangeRateEntity entity =new ExchangeRateEntity();
		entity =this.changeToEntity(vo);
		entity.save(entity);
	}


	@Override
	public void delete(ExchangeRateVO vo) {
		ExchangeRateEntity entity =new ExchangeRateEntity();
		entity =this.changeToEntity(vo);
		entity.delete(entity);
	}

	@Override
	public List<ExchangeRateVO> findByCondition(String name, String code,
			String date) {
		List<ExchangeRateVO> listVO=new ArrayList<ExchangeRateVO>();
		ExchangeRateEntity entity=new ExchangeRateEntity();
		List<ExchangeRateEntity> list =entity.findByCondition(name, code, date);
		if(null!=list && list.size()>0){
			for(ExchangeRateEntity en: list){
				ExchangeRateVO vo =this.changeToVO(en);
				listVO.add(vo);
			}
		}
		return listVO;
	}
	
	
	private ExchangeRateVO changeToVO(ExchangeRateEntity en) {
		ExchangeRateVO vo =new ExchangeRateVO();
		vo.setId(en.getId());
		vo.setCode(en.getCode());
		vo.setName(en.getName());
		vo.setDate(en.getDate());
		vo.setRefePrice(en.getRefePrice());
		vo.setLastTime(en.getLastTime());
		return vo;
	}


	private ExchangeRateEntity changeToEntity(ExchangeRateVO vo) {
		ExchangeRateEntity en =new ExchangeRateEntity();
		en.setId(vo.getId());
		en.setCode(vo.getCode());
		en.setName(vo.getName());
		en.setDate(vo.getDate());
		en.setRefePrice(vo.getRefePrice());
		en.setLastTime(vo.getLastTime());
		return en;
	}

}
